package com.pactera.asmp.server.restfullapi;

import com.pactera.asmp.server.common.constants.PermissionCode;
import com.pactera.asmp.server.entity.ProjectModuleBatchDTO;
import com.pactera.asmp.server.entity.ProjectModuleCommonBatchDTO;
import com.pactera.asmp.server.entity.ProjectModuleSearch;
import com.pactera.asmp.server.entity.ResponseResult;
import com.pactera.asmp.server.service.ProjectModuleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/project_module")
public class RestfullProjectModuleApi {

    private static final Logger logger = LoggerFactory.getLogger(RestfullProjectModuleApi.class);

    @Autowired
    private ProjectModuleService projectModuleService;


    // 增删改整合
    @PostMapping(value = "/batch")
    public ResponseResult batch(@RequestBody @Validated ProjectModuleBatchDTO batch) {
        logger.info("/api/v1/project_module/batch");
        return projectModuleService.batch(batch);
    }

    @PostMapping(value = "/list")
    public ResponseResult list(@RequestBody ProjectModuleSearch search) {
        logger.info("/api/v1/project_module/list");
        return projectModuleService.select(search);
    }

    @RequiresPermissions({PermissionCode.TEST_TASK})
    @PostMapping(value = "/listScripts")
    public ResponseResult listScripts(@RequestBody ProjectModuleSearch search) {
        logger.info("/api/v1/project_module/listScripts");
        return projectModuleService.selectListScripts(search);
    }

    @GetMapping(value = "/allByProjectId")
    public ResponseResult selectAvailableByProjectId(@RequestParam("projectId")Integer projectId) {
        logger.info("/api/v1/project_module/allByProjectId :{}", projectId);
        return projectModuleService.selectAvailableByProjectId(projectId);
    }


    @PostMapping(value = "/batchCommon")
    public ResponseResult batchCommon(@RequestBody @Validated ProjectModuleCommonBatchDTO batch) {
        logger.info("/api/v1/project_module/batchCommon");
        return projectModuleService.batchCommon(batch);
    }

    @GetMapping(value = "/listCommon")
    public ResponseResult listCommon() {
        logger.info("/api/v1/project_module/listCommon");
        return projectModuleService.selectCommon();
    }
}
